package org.ww.order.web;

import com.alipay.api.AlipayApiException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.ww.order.config.AlipayTemplate;
import org.ww.order.service.OrderService;
import org.ww.order.vo.PayVo;

/**
 * @program: gmall
 * @description:
 * @author: ww
 * @create: 2024-11-01 15:42
 **/
@Slf4j
@Controller
public class PayWebController {

    @Autowired
    private OrderService orderService;
    @Autowired
    private AlipayTemplate alipayTemplate;

    @ResponseBody
    @GetMapping(value = "/aliPayOrder",produces = "text/html")
    public String alipay(@RequestParam("orderSn") String orderSn) throws AlipayApiException {
        PayVo payVo = orderService.getPayVo(orderSn);
        log.info("支付宝待支付商品信息：【{}】",payVo);
        //将返回的文本构造成html
        String pay = alipayTemplate.pay(payVo);
        return pay;
    }

}
